package cn.ycc1.mymiddle.chat;

import org.springframework.ai.image.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ycc
 * @date 2025/5/1
 */
@RestController
@RequestMapping("/image-model")
public class ImageModelController {
    private final ImageModel imageModel;

    ImageModelController(ImageModel imageModel) {
        this.imageModel = imageModel;
    }

    @RequestMapping("/image")
    public String image(String input) {
        ImageOptions options = ImageOptionsBuilder.builder()
//                .model("dall-e-3")
                .build();

        ImagePrompt imagePrompt = new ImagePrompt(input, options);
        ImageResponse response = imageModel.call(imagePrompt);
        String imageUrl = response.getResult().getOutput().getUrl();

        return "redirect:" + imageUrl;
    }

    @RequestMapping("/imageWithOptions")
    public String imageWithOptions(String input) {
        ImageOptions options = ImageOptionsBuilder.builder()
                .model("dall-e-3")
                .responseFormat("1024x1024")
                .build();

        ImagePrompt imagePrompt = new ImagePrompt(input, options);
        ImageResponse response = imageModel.call(imagePrompt);
        String imageUrl = response.getResult().getOutput().getUrl();

        return "redirect:" + imageUrl;
    }
}
